package day15;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author Xiao
 * @date 2021/8/9
 */
public class InetAddressDemo01 {
    /**
     * 常用方法
     * 	static InetAddress getByName(String host)：确定主机名称的IP地址。主机名称可以是机器名称，也可以是IP地址
     * 	String getHostName()：获取此IP地址的主机名
     * 	String getHostAddress()：返回文本显示中的IP地址字符串
     */
    public static void main(String[] args) throws UnknownHostException {
//        InetAddress address = InetAddress.getByName("192.168.3.28");
        InetAddress address = InetAddress.getByName("Qz");
//        InetAddress address = InetAddress.getByName("localhost");
//        InetAddress address = InetAddress.getByName("127.0.0.1");
        String hostName = address.getHostName();
        String hostAddress = address.getHostAddress();
        System.out.println(address);        //Qz/192.168.3.28
        System.out.println(hostName);       //Qz
        System.out.println(hostAddress);    //192.168.3.28
    }
}
